import * as echarts from 'echarts';

export async function useEChartsTheme(themePath: string): Promise<string> {
  try {
    const response = await fetch(themePath);
    if (!response.ok) {
      throw new Error(`HTTP error: ${response.status}`);
    }
    const theme = await response.json();
    const themeName = 'customized'; // 确保主题名称一致
    echarts.registerTheme(themeName, theme);
    // console.log('主题注册成功:', themeName); // 调试输出
    // console.log('注册的主题内容:', theme); // 打印主题内容
    return themeName;
  } catch (error) {
    console.error('注册主题失败:', error);
    throw error;
  }
}
